﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;


namespace GCard
{
    class XY
    {
        public static string GetMD5(string str)
        {
            //获得md5对象
            MD5 md5 = MD5.Create();
            //将要加密的字符串转化为字节数组
            byte[] buffer = Encoding.Default.GetBytes(str);
            //返回 加密好的字节数组
            byte[] md5buffer = md5.ComputeHash(buffer);
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < md5buffer.Length; i++)
            {
                sb.Append(md5buffer[i].ToString("x2"));
            }
            //将加密好的字节数组转化成字符串
            return sb.ToString();
            //string res = string.Empty;//string res="";
            //for (int i = 0; i < md5buffer.Length; i++)
            //{
            //    //十进制---->十六进制
            //res += md5buffer[i].ToString("x2");
            //}
            //return res;
        }
    }
}
